﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace WebAPI.CustomFilter
{
    /// <summary>
    /// 权限验证过滤器
    /// </summary>
    public class AuthFilter : IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            //if (context.Filters.Contains(new MyNoAuthentication()))
            //{
            //    return;
            //}
            var authorize = context.HttpContext.Request.Headers["token"];
            if (string.IsNullOrWhiteSpace(authorize))
            {
                context.Result = new JsonResult(new { code = 500, message = "token不能为空" });
                return;
            }
            //if (!MemoryCacheHelper.Exists(authorize))
            //{
            //    context.Result = new JsonResult("无效的授权信息或授权信息已过期");
            //    return;
            //}
        }
    }
}
